home *** CD-ROM | disk | FTP | other *** search
/ Beginning Mac Programming / Beginning Mac Programming.bin / Open Me for REALbasic 3 / REALbasic 3.2 / Example Projects / Applications / SixPack SDK 1.0dr1 / Developer's Guide next >
Text File  |  1999-12-15  |  8KB  |  193 lines

  1. SixPack, version: 1.0dr1 - Developers Guide
  2.  
  3. copyright © 1999 simple/CHAOS
  4.  
  5. http://www.trafficstudio.com/sixpack
  6. sixpack@trafficstudio.com
  7.  
  8. Requires: REALbasic 2.1a17 or higher
  9.  
  10. SixPack is subject to the "SixPack Open Source License"
  11.  
  12. Development Notes
  13.  
  14. This is the initial developer release of SixPack, and as such there is much that is not finished, including the documentation. This document serves as a "sketch" for documenting SixPack and will be expanded as development continues. If there are areas that you feel need attention, please let me know, so that, if anything, I can put it on my TODO list.
  15.  
  16. For instructions on basic usage of the SixPack editor, please see the accompanying "Read Me" file. For licensing details, please consult the "License" file.
  17.  
  18. SixPack is open source and I welcome your fixes, enhancements, etc. If you wish to contribute to SixPack, please note the following;
  19.  
  20. -Currently SixPack is being developed in REALbasic 2.1a17 (Standard).
  21.  
  22. -If your code contribution is very specific (like a few lines or sub or function) send it to me as text in an email.
  23.  
  24. -If your contribution is larger, you can send REALbasic class, module, or project files (binhex it).
  25.  
  26. -Document your code.
  27.  
  28. -All code must work on 68k/PPC.
  29.  
  30. -No XCMDs/XFCNs, Toolbox calls, or Plug-ins (if you are really set on using one of these, contact me and talk me into it).
  31.  
  32. -Feature requests are ok, but new code is better.
  33.  
  34. Future enhancements/wish list; exception handling, find and replace, printing, save via FTP, syntax highlighting in source view, DTD support, some sort of XSL support (though IMHO XSL is, at present, a giant mess) and non-recursive versions of the parser/source output methods.
  35.  
  36. Questions, comments, rants & raves to sixpack@trafficstudio.com
  37.  
  38. Enjoy,
  39.  
  40. Geoff Strom
  41. simple/CHAOS
  42.  
  43. Highlights of the XML Classes
  44.  
  45. In order to use the SixPack parser in your own applications you will need the following (all of which are in the "XML Classes" folder inside the SixPack project file):
  46.  
  47. Classes
  48. -CXMLObject
  49. -CXMLFragment
  50. -CXMLAssocStringArray
  51. -CXMLAssocObjectArray
  52.  
  53. Modules
  54. -XMLParserModule
  55.  
  56. There are two basic methods for use, ParseXML and MakeXMLSource
  57.  
  58. Example:
  59.  
  60. dim doc as CXMLObject
  61. dim s as string
  62. doc=ParseXML("<root>hello world!</root>")
  63. // doc is now a DOM that represents the XML that was parsed
  64. s=MakeXMLSource(doc) // let's make the DOM back into source
  65. // now s="<root>hello world!</root>"
  66.  
  67. XML Class Details
  68.  
  69. CXMLObject methods
  70.  
  71. .init(type as string)
  72.  
  73. possible values for type; "root", "element", "comment", "pi", "cdata", "chardata"
  74.  
  75. The CXMLObject class is the heart of the parser and is the device by which a simple DOM is implemented (the DOM implementation used in SixPack does not meet W3's proposal for DOM Level 1, but for our purposes it works just fine).
  76.  
  77. The CXMLObject has the following properties, which depending on how it is initialized may be nil pointers:
  78.  
  79. name as string(used in "root" and "element" types only)
  80.  
  81. type as string (must be one of these values: "root", "element", "comment", "pi", "cdata", "chardata")
  82.  
  83. value as string (used in "comment", "pi", "cdata", "chardata" types only)
  84.  
  85. uid as integer (every CXMLObject has a unique ID number)
  86.  
  87. attributes as CXMLAssocStringArray (used in "root" and "element" types only, for all 
  88. other types this will be nil)
  89.  
  90. contents as CXMLAssocObjectArray (used in "root" and "element" types only, for all other types this will be nil)
  91.  
  92. index as CXMLAssocObjectArray  (used in "root" type only, for all other types this will be nil)
  93.  
  94. Nearly every operation you undertake on a DOM will be accomplished primarily through the root's index property (which gives you access to every object in the DOM tree). Please see the associative array discussion below for traversal details. You can also walk through the DOM tree by way of an objects "contents" array.
  95.  
  96. CXMLFragment
  97.  
  98. The CXMLFragment class is only used internally by the parser and has no public functions.
  99.  
  100. CXMLAssocStringArray methods
  101.  
  102. set(key as string,value as string)
  103. get(key as string) as string
  104. remove(key as string)
  105. getkey(index as integer) as string
  106. keycount() as integer
  107.  
  108. CXMLAssocObjectArray methods
  109.  
  110. set(key as string,value as CXMLObject)
  111. get(key as string) as CXMLObject
  112. remove(key as string)
  113. getkey(index as integer) as string
  114. keycount() as integer
  115.  
  116. The two array classes behave exactly the same, the only difference is that one provides an associative array for string values and one is an associative array for CXMLObjects. Both are 1 based arrays and cannot be operated on by REALbasic's built-in array methods.
  117.  
  118. While you would typically use the set, get, & remove methods to operate on the array members, there are many times when we don't know what the key is. Fortunately, we can determine the key by use of the getkey method and in conjunction with the keycount method we can traverse these arrays quite easily.
  119.  
  120. Example:
  121.  
  122. // let's pretend that AssocArray was already dimmed and populated as a CXMLAssocStringArray
  123. dim i as integer
  124. dim s as string
  125. for i=1 to AssocArray.keycount
  126.   s = s + AssocArray.get(AssocArray.getkey(i))
  127. next
  128.  
  129. XMLParserModule methods
  130.  
  131. ParseXML(source as string) as CXMLObject
  132.  
  133. source must be well formed XML, returns a "root" CXMLObject
  134.  
  135. example:
  136.  
  137. dim doc as CXMLObject
  138. doc=ParseXML("<root>hello world!</root>")
  139.  
  140. MakeXMLSource(tag as CXMLObject) as string
  141.  
  142. tag must be an "element" or "root" CXMLObject, returns well formed XML
  143.  
  144. example:
  145.  
  146. dim s as string
  147. s=MakeXMLSource(doc) // s="<root>hello world!</root>"
  148.  
  149. MakeXMLObjectListBox(doc as CXMLObject, box as ListBox)
  150.  
  151. doc must be a "root" CXMLObject, box must be a two column (100%,0%) hierarchical ListBox, use of this method also requires that the following 16x16 pixel pictures be available in the project file: element, comment, pi, cdata, text
  152.  
  153. In order to display all DOM elements, the ListBox must also call MakeXMLObjectListBox during its "Expand" event
  154.  
  155. Example:
  156.  
  157. Sub ExpandRow(Row As Integer)
  158.   MakeObjectListBox(TheDOM.index.get(me.cell(row,1)),me)
  159. End Sub
  160.  
  161. GetParent(doc as CXMLObject, searchID as string) as CXMLObject
  162.  
  163. doc must be a "root" CXMLObject, searchID is the uid of the CXMLObject whose parent object you want to find, returns an "element" or "root" CXMLObject if successful or nil if the search fails
  164.  
  165. DeleteObject(doc as CXMLObject, targetID as string) as boolean
  166.  
  167. doc must be a "root" CXMLObject, targetID is the uid of the CXMLObject you want to delete, returns true if successful or false if the deletion fails
  168.  
  169. AddObject(doc as CXMLObject, NewObj as CXMLObject, targetID as string) as integer
  170.  
  171. doc must be a "root" CXMLObject, NewObj can be any CXMLObject except "root", targetID is the uid of the object you wish to add NewObj to, returns the uid of the object that NewObj was actually added to (as integer), if the add fails it returns -1
  172.  
  173. note: even though the targetID is specified, you can only add objects to "element" and "root" type objects, so if the targetID is for a non-element type object (like "comment") AddObject will find targetID's parent and add the NewObj to it instead
  174.  
  175. Highlights of the Support Classes
  176.  
  177. CBetterEditField
  178.  
  179. This is an improved EditField subclass that adds support for single level undo/redo and select all. To use it simply put the class in your project and change the "super" of any editfields you use to CBetterEditField.
  180.  
  181. Once a CBetterEditField based editfield regains focus (after losing it) the undo cache is cleared.
  182.  
  183. You must have the following menuitems in your project: EditUndo, EditCut, EditCopy, EditPaste, EditClear, EditSelectAll.
  184.  
  185. In the future, this class will likely be enhanced to add support for multi-level undo.
  186.  
  187. Note
  188.  
  189. The SixPack editor does make use of a 3rd party class for some interface elements. The class is CPictureButton written by Bjorn Eiriksson and it is a protected class.
  190.  
  191. copyright © 1999 simple/CHAOS
  192. all rights reserved
  193.